#include <modules\graphics\color.h>

namespace DelGE
{
	namespace Modules
	{
		namespace Graphics
		{
			Color::Color()
			{
				this->color[0]	=
				this->color[1]	=
				this->color[2]	=
				this->color[3]	= 255;
			}

			Color::Color(int iRed, int iGreen, int iBlue)
			{
				if (iRed < DELGE_GRAPHICSCOLOR_VALUE_MIN) iRed = DELGE_GRAPHICSCOLOR_VALUE_MIN;
				if (iRed > DELGE_GRAPHICSCOLOR_VALUE_MAX) iRed = DELGE_GRAPHICSCOLOR_VALUE_MAX;

				if (iGreen < DELGE_GRAPHICSCOLOR_VALUE_MIN) iGreen = DELGE_GRAPHICSCOLOR_VALUE_MIN;
				if (iGreen > DELGE_GRAPHICSCOLOR_VALUE_MAX) iGreen = DELGE_GRAPHICSCOLOR_VALUE_MAX;

				if (iBlue < DELGE_GRAPHICSCOLOR_VALUE_MIN) iBlue = DELGE_GRAPHICSCOLOR_VALUE_MIN;
				if (iBlue > DELGE_GRAPHICSCOLOR_VALUE_MAX) iBlue = DELGE_GRAPHICSCOLOR_VALUE_MAX;

				this->color[0]	= iRed;
				this->color[1]	= iGreen;
				this->color[2]	= iBlue;
				this->color[3]	= 255;
			}
			
			Color::Color(int iRed, int iGreen, int iBlue, int iAlpha)
			{
				if (iRed < DELGE_GRAPHICSCOLOR_VALUE_MIN) iRed = DELGE_GRAPHICSCOLOR_VALUE_MIN;
				if (iRed > DELGE_GRAPHICSCOLOR_VALUE_MAX) iRed = DELGE_GRAPHICSCOLOR_VALUE_MAX;

				if (iGreen < DELGE_GRAPHICSCOLOR_VALUE_MIN) iGreen = DELGE_GRAPHICSCOLOR_VALUE_MIN;
				if (iGreen > DELGE_GRAPHICSCOLOR_VALUE_MAX) iGreen = DELGE_GRAPHICSCOLOR_VALUE_MAX;

				if (iBlue < DELGE_GRAPHICSCOLOR_VALUE_MIN) iBlue = DELGE_GRAPHICSCOLOR_VALUE_MIN;
				if (iBlue > DELGE_GRAPHICSCOLOR_VALUE_MAX) iBlue = DELGE_GRAPHICSCOLOR_VALUE_MAX;

				if (iAlpha < DELGE_GRAPHICSCOLOR_VALUE_MIN) iAlpha = DELGE_GRAPHICSCOLOR_VALUE_MIN;
				if (iAlpha > DELGE_GRAPHICSCOLOR_VALUE_MAX) iAlpha = DELGE_GRAPHICSCOLOR_VALUE_MAX;

				this->color[0]	= iRed;
				this->color[1]	= iGreen;
				this->color[2]	= iBlue;
				this->color[3]	= iAlpha;
			}

			Color::~Color()
			{
				this->color[0]	=
				this->color[1]	=
				this->color[2]	=
				this->color[3]	= 0;
			}

			float Color::GetRedScalar() const
			{
				return (float)this->color[0] / (float)DELGE_GRAPHICSCOLOR_VALUE_MAX;
			}

			float Color::GetGreenScalar() const
			{
				return (float)this->color[1] / (float)DELGE_GRAPHICSCOLOR_VALUE_MAX;
			}

			float Color::GetBlueScalar() const
			{
				return (float)this->color[2] / (float)DELGE_GRAPHICSCOLOR_VALUE_MAX;
			}

			float Color::GetAlphaScalar() const
			{
				return (float)this->color[3] / (float)DELGE_GRAPHICSCOLOR_VALUE_MAX;
			}

			int& Color::operator [](unsigned int uiIndex)
			{
				if (uiIndex > 3) uiIndex = 3;
				return this->color[uiIndex];
			}

			int Color::operator [](unsigned int uiIndex) const
			{
				if (uiIndex > 3) uiIndex = 3;
				return this->color[uiIndex];
			}
		}
	}
}